package com.jk.controller;

import com.github.pagehelper.PageInfo;
import com.jk.common.util.EasyUIResult;
import com.jk.item.pojo.Item;
import com.jk.item.service.ItemService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author cuiP
 * Created by JK on 2017/6/12.
 */
@Controller
@RequestMapping("/item")
public class ItemController {

    @Resource
    private ItemService itemService;

    @RequestMapping(value = "/{itemId}", method = RequestMethod.GET)
    @ResponseBody
    public Item getItemById(@PathVariable Long itemId){
        return itemService.findById(itemId);
    }

    /**
     * 分页查询商品列表
     * @param page
     * @param rows
     * @return
     */
    @ResponseBody
    @RequestMapping("/list")
    public EasyUIResult list(@RequestParam(value = "page", defaultValue = "1") int page, int rows){
        PageInfo<Item> pageInfo = itemService.findPage(page, rows, null);
        return new EasyUIResult(pageInfo.getTotal(), pageInfo.getList());
    }
}
